package com.sailfish.springbootdemo.service.db2.impl;

import com.sailfish.springbootdemo.dao.db2.PcbCapacityDataHistoryDao;
import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db2.PcbCapacityData;
import com.sailfish.springbootdemo.pojo.db2.PcbCapacityDataHistory;
import com.sailfish.springbootdemo.pojo.db2.PcbCapacityParam;
import com.sailfish.springbootdemo.service.db2.PcbCapacityDataHistoryService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

public class PcbCapacityDataHistoryServiceImpl implements PcbCapacityDataHistoryService {

    @Autowired
    PcbCapacityDataHistoryDao pcbCapacityDataHistoryDao;

    @Override
    public List<PcbCapacityDataHistory> getAll() {
        return null;
    }

    @Transactional(transactionManager = "MysqlTransactionManager2")
    @Override
    public Result insert(List<PcbCapacityDataHistory> params) {
        try {
            int count = pcbCapacityDataHistoryDao.insertBatch(params);
            return ResultUtil.success(params);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result delete(Integer id) {
        return null;
    }

    @Transactional(transactionManager = "MysqlTransactionManager2")
    @Override
    public Result delete(String pcbDataVersionName) {
        try {
            int count = pcbCapacityDataHistoryDao.deleteByVersionName(pcbDataVersionName);
            return ResultUtil.success(null);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
